<?php
namespace Api\Controller;

use Think\Controller;

class CategoryController extends CommonController
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 获取所有分类
     * @return [type] [description]
     */
    public function index()
    {
        $categorys = D('Api/Category', 'Service')->getAllTree();

        success($categorys);
    }

    /**
     * 获取所有父分类
     * @return [type] [description]
     */
    public function getParents()
    {
        $categorys = D('Api/Category', 'Service')->getParents();

        success($categorys);
    }

    // 获取子分类
    public function getChilds()
    {
        $parent_id = I('post.parent_id', 1, 'intval');
        if (!$parent_id) {
            error(1003, '一级分类id必须大于0');
        }

        $categorys = D('Api/Category', 'Service')->getChilds($parent_id);

        success($categorys);
    }
}
